package com.zhidisoft.crm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhidisoft.crm.dao.ISysUserMapper;
import com.zhidisoft.crm.entity.SysUser;
import com.zhidisoft.crm.service.ISysUserService;
import com.zhidisoft.crm.vo.PageVo;
import com.zhidisoft.crm.vo.SysUserVo;
@Service
@Transactional
public class SysUserImpl implements ISysUserService{
	@Autowired
	ISysUserMapper dao;
	/**
	 * 添加用户
	 */
	@Override
	public void save(SysUserVo user) {
		dao.save(user);
	}
	/**
	 * 分页查询
	 */
	@Override
	public PageVo pageList(Integer pageNum, Integer pageSize) {
		PageVo pageVo = new PageVo();
		pageVo.setPageNum(pageNum);
		pageVo.setPageSize(pageSize);
		int beginIndex = (pageNum - 1) * pageSize;
		int endIndex = beginIndex + pageSize;
		pageVo.setList(dao.pageList(beginIndex, endIndex));
		//pageVo.setList(dao.pageList((pageNum - 1) * pageSize, pageSize));
		pageVo.setTotalCount((int) dao.totalCount());
		return pageVo;
	}
	/**
	 * 根据id删除用户
	 */
	@Override
	public void delete(String id) {
		dao.delete(id);
	}
	/**
	 * 根据id修改用户信息
	 */
	@Override
	public void update(SysUser user) {
		dao.update(user);
	}
	
	/**
	 * 根据id查询一条数据
	 */
	@Override
	public SysUserVo findId(String id) {
		return dao.findId(id);
	}
	@Override
	public SysUserVo selectByName(String username) {
		return dao.selectByName(username);
	}
	

}
